package com.example.demo.controller;

import com.example.demo.pojo.Result;
import com.example.demo.pojo.dto.CommentAddDTO;
import com.example.demo.pojo.dto.ForumAddDTO;
import com.example.demo.pojo.vo.ForumDetailVO;
import com.example.demo.pojo.vo.ForumVO;
import com.example.demo.service.ForumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/polycystic/forum")
public class ForumController {

    @Autowired
    private ForumService forumService;

    @GetMapping("/list")
    public Result<ForumVO> list(){
        ForumVO forumVO=forumService.list();
        return Result.success(forumVO);
    }

    @PostMapping("/add")
    public Result add(@RequestBody ForumAddDTO forumAddDTO){
        forumService.add(forumAddDTO);
        return Result.success();
    }

    @GetMapping("/support")
    public Result updateSupport(Long id,Integer support){
        forumService.updateSupport(id,support);
        return Result.success();
    }

    @GetMapping("/detail/{forumId}")
    public Result<ForumDetailVO> detail(@PathVariable Long forumId){
        ForumDetailVO forumDetailVO=forumService.getDetail(forumId);
        return Result.success(forumDetailVO);
    }

    @PostMapping("/addComment")
    public Result addComment(@RequestBody CommentAddDTO commentAddDTO){
        forumService.addComment(commentAddDTO);
        return Result.success();
    }
}
